package com.shamine.kuaiqiao.blink.tools

import android.content.Context
import android.net.ConnectivityManager

/**
 * Created by caine on 11/11/17.
 */
class NetworkTool {
    /**
     * 是否连接
     * @param context
     * @return
     */
    fun isConnected(context: Context): Boolean {
        val manager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
        val networkInfo = manager.activeNetworkInfo
        return networkInfo != null && networkInfo.isConnected
    }

//    /**
//     * 检查网络状态和类型
//     * @return 返回网络类型:0为数据，1为wifi
//     */
//    fun checkNetWorkType(context: Context?): Int {
//        if (context != null) {
//            //获取手机所有连接管理对象
//            val manager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
//            //获取NetworkInfo对象
//            val networkInfo = manager.activeNetworkInfo
//            if (networkInfo != null && networkInfo.isAvailable) {
//                when (networkInfo.type) {
//                    ConnectivityManager.TYPE_MOBILE -> return 0
//                    ConnectivityManager.TYPE_WIFI -> return 1
//                }
//            }
//        }
//        return -1
//    }

}